package org.jeecg.modules.flow.callback.inbound.other;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.business.transfer.entity.PaperPurchase;
import org.jeecg.modules.business.transfer.mapper.PaperPurchaseMapper;
import org.jeecg.modules.flow.sys.common.BaseCustomBeanRun;
import org.jeecg.modules.flow.sys.entity.dto.BaseFlowDto;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 纸筒采购任务关闭bean
 *
 * @author lumingyi
 * @version 1.0.0
 * @since 2023-11-14
 */
@Component
@Slf4j
public class R47PaperPurchaseCloseBeforeBean<T> extends BaseCustomBeanRun<T> {
    @Resource
    private PaperPurchaseMapper paperPurchaseMapper;

    @Override
    public void actureRun() {
        BaseFlowDto baseFlowDto = this.getBaseFlowDto();
        // 获取请求参数
        baseFlowDto.translateClass(JSONObject.class);
        String taskId = baseFlowDto.getInfoId();
        PaperPurchase task = paperPurchaseMapper.selectById(taskId);
        if (ObjectUtil.isEmpty(task)) {
            throw new JeecgBootException("纸筒采购任务不存在!");
        }
        task.setDocumentStatus("-1");   // 状态改为手工关闭
        paperPurchaseMapper.updateById(task);
        // 当前前端调用业务需要你返回的
        baseFlowDto.setResult(Result.OK());
        // id是保存业务记录的id。用于生成业务流程信息记录
        baseFlowDto.setInfoId(taskId);
    }
}
